package com.lwb.ztx.videos.model;

import com.lwb.ztx.api.Api;
import com.lwb.ztx.bean.VideoBean;
import com.lwb.ztx.bean.VideoMainBean;
import com.lwb.ztx.utils.LogUtils;
import com.lwb.ztx.utils.OkHttpUtils;

import java.util.List;

/**
 * Created by luweibin on 2016/5/30.
 */
public class VideoModelImpl implements VideoModel {
    private OnVideoLoadFinishListener listener;

    public VideoModelImpl(OnVideoLoadFinishListener listener) {
        this.listener = listener;
    }

    @Override
    public void loadVideos(String url,final int page) {
        OkHttpUtils.ResultCallback<String> loadNewsCallback = new OkHttpUtils.ResultCallback<String>() {
            @Override
            public void onSuccess(String response) {
                VideoMainBean bean = VideoReadUtils.readVideoMainJson(response);
                LogUtils.d(bean.toString());
                listener.onSuccess(bean,page);
            }

            @Override
            public void onFailure(Exception e) {
                listener.onFailure();
            }
        };
        OkHttpUtils.get(url, loadNewsCallback);
    }

    public interface OnVideoLoadFinishListener{
        void onSuccess(VideoMainBean bean, int page);
        void onFailure();
    }
}
